angular.module('imsApp').controller('appStatisticsController', ['$scope', '$rootScope', '$state', 'AppManager', function ($scope, $rootScope, $state, AppManager) {
    $scope.search = {
        appId: $state.params.appId,
        timeType: $state.params.timeType || 'day',
        pageNo: $state.params.pageNo || 1,
        pageSize: $state.params.pageSize || 10,
        adStyle: $state.params.adStyle
    };
    $scope.adStyle = {81: $scope.table[81], 82: $scope.table[82], 83: $scope.table[83], 84: $scope.table[84]}
    $scope.paginationDetail = {
        currentPage: $scope.search.pageNo,
        itemsPerPage: $scope.search.pageSize,
        pagesLength: 9,
        search: 0,
        onChange: function () {
            $scope.search.pageNo = this.currentPage;
            $scope.search.pageSize = this.itemsPerPage;
            $state.go($state.current.name, $scope.search)



        }
    };

    $scope.deletes=function (key) {
        $scope.search[key]=null;
        $state.go($state.current.name, $scope.search)

    }



    AppManager.appStat([$scope.search.appId, $scope.paginationDetail.currentPage, $scope.paginationDetail.itemsPerPage], {
        timeType: $scope.search.timeType,
        adStyle: $scope.search.adStyle
    }).then(function (result) {
        $scope.appList = result.data;
        if ($scope.appList.c == "s") {
            $scope.lists = $scope.appList.pageList;
            $scope.total = $scope.appList.countStat;
            $scope.paginationDetail.totalItems = $scope.appList.total;
            $scope.title = $scope.appList.title;
            $scope.uTime = $scope.appList.uTime;
        }
    })

    $scope.timeTypeChange = function (type) {
        $scope.search.pageNo = 1;
        $scope.search.timeType = type;
        $state.go($state.current.name, $scope.search)


    }

    $scope.searchChange=function () {
        $state.go($state.current.name, $scope.search)
    }

}])

